<template>
  <div class="login">
    <form>
    <div class="box">
      <h2>登录</h2>
      <div class="inputs">
        <div><input name="email" type="email" placeholder="Email" @keyup="emailValue"/></div>
        <div>
          <input
            name="password"
            type="password"
            placeholder="PassWord"
            autocomplete="off"
            @keyup="passwordValue"
          />
        </div>
      </div>
      <div class="button">
        <div>
          <p @click="pass">忘记密码？</p>
          <p @click="sing">没有账号？</p>
        </div>
        <button type="button" @click="toLogin">登录</button>
      </div>
    </div>
    </form>
  </div>
</template>

<script>

import {useRouter } from 'vue-router';
import {login} from "@/api/login"
import { inject,ref } from 'vue';
import {Toast } from "vant"
export default {
  name: "Login",
  setup() {
    const axios = inject("$http")
    const log = Toast
    // 路由跳转 
    let router = useRouter()
    function sing(){
      router.push("/sing")
    }
    function pass(){
      router.push("/pass")
    }
    // 获取数据
    let email = ref('')
    function emailValue(e){
      email.value = e.target.value
    }
    let password = ref('')
    function passwordValue(e){
      password.value = e.target.value
    }

    // 登录
    function toLogin(){
      let inputs = [email.value,password.value]
      login(inputs,router,axios,log,{email:email.value,password:password.value})
    }


    return {
      sing,pass,
      email,emailValue,
      password,passwordValue,
      toLogin,
    }
  },
};
</script>

<style scoped lang="scss">
.login {
  width: 100vw;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background: url("1.jpg") no-repeat 0 0/100%;
  .box {
    width: 50vh;
    height: 50vh;
    border-radius: 15px;
    background: rgba($color: white, $alpha: .7);
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    h2 {
      text-align: center;
      font-size: 24px;
    }
    .inputs {
      width: 100%;
      display: flex;
      flex-direction: column;
      align-items: center;
      div {
        width: 70%;
        padding: 3%;
        input {
          border: 1px solid #aaa;
          border-radius: 15px;
          outline: none;
          width: 100%;
          padding: 4%;
        }
      }
    }
    .button {
      width: 100%;
      height: 70px;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: space-between;
      div {
        width: 80%;
        display: flex;
        justify-content: space-evenly;
        p {
          color: rgb(82, 82, 82);
          font-size: 15px;
        }
      }
      button {
        width: 80px;
        height: 30px;
        border-radius: 5px;
        border: none;
        background: rgba($color: #ff0000, $alpha: .7);
      }
    }
  }
}
</style>